<?php
//No direct access
defined('_JEXEC') or die('Restricted access');

jimport('joomla.application.component.view');

class OwnserviceViewTransactions extends JView
{
	function display($tpl=null) {

		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$db			= & JFactory::getDBO();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');
		$pathway  	= & $mainframe->getPathway();
		
		//Set page title information
		$menus		= &JSite::getMenu();
		$menu		= $menus->getActive();
		
		//Get vars
		$gid		= $user->gid;
		$level		= $ownuser->get('level_id');
		$params = $mainframe->getParams('com_ownservice');
		$task		= JRequest::getVar('task', '');
		$cid		= JRequest::getVar('cid', array());
		
		if($level == 3){
			$this->setLayout('receivingtransfer');
		}

		//check permission for manage transactions
		if($user->gid < 25) {
			if (!Ownservice::checkAccess( 'transaction', 'manage' )) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//Customer Transfers
		if( $this->getLayout() == 'customertransfers' ) {
			$this->_displayCustomerTransfers($tpl);
			return;
		}
		
		//Paid
		if( $this->getLayout() == 'paidtransactions' ) {
			$this->_displayPaidTransactions($tpl);
			return;
		}

		// Request Approval
		if( $this->getLayout() == 'requestapproval' ) {
			$this->_displayrequestapproval($tpl);
			return;
		}

		// Select Approve & Select IR
		if( $task == 'elementrequestapproval' ) {
			$this->setLayout('elementrequestapproval');
			$this->_displayElementrequestapproval($tpl,$cid);
			return;
		}
		
		// Request Approval (Corrected)
		if( $this->getLayout() == 'requestapprovalcorrected' ) {
			$this->_displayrequestapprovalcorrected($tpl);
			return;
		}
		
		// Transferring
		if( ($this->getLayout() == 'receivingtransfer')) {
			$this->_displayReceivingtransfer($tpl);
			return;
		}

		// Faile
		if( $this->getLayout() == 'failedtransactions' )
		{
			$this->_displayfailedtransactions($tpl);
			return;
		}
		
		// Corrected
		if( $this->getLayout() == 'correctedtransactions')
		{
			$this->_displaycorrectedtransactions($tpl);
			return;
		}

		// Cancel
		if( $this->getLayout() == 'cancelledtransactions' )
		{
			$this->_displaycancelledtransactions($tpl);
			return;
		}

		//Transferring Transaction (center manager + md)
		if( $this->getLayout() == 'transferring' )
		{
			$this->_displaytransferring($tpl);
			return;
		}

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		
		$filter_branch		= $mainframe->getUserStateFromRequest($option.'.transaction.filter_branch','filter_branch',0,'int' );
		$filter_order			= $mainframe->getUserStateFromRequest($option.'.transaction.filter_order', 'filter_order', 't.created', 'cmd');
		$filter_order_Dir	= $mainframe->getUserStateFromRequest($option.'.transaction.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search				= $mainframe->getUserStateFromRequest($option.'.transaction.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);
		
		//get data from the model
		$model 		= $this->getModel();
		$rows 		= & $this->get('Data');
		$total			= & $this->get('Total');
		$pageNav	= & $this->get('Pagination');
		$branches 	= & $this->get('Branches');
		
		// because the application sets a default page title, we need to get it
		// right from the menu item itself
		if (is_object( $menu )) {
			$menu_params = new JParameter( $menu->params );
			if (!$menu_params->get( 'page_title')) {
				$params->set('page_title',	JText::_('OWNSERVICE_TODAYS_TRANSACTIONS'));
			}
		} else {
			$params->set('page_title',	JText::_('OWNSERVICE_TODAYS_TRANSACTIONS'));
		}
		$document->setTitle( $params->get( 'page_title' ) );
		
		$params->def( 'show_page_title', 1 );
		
		// Create a user access object for the current user
		$access = new stdClass();
		$access->canView		= ($user->gid < 25)? Ownservice::checkAccess('transaction','view','transaction','all'):1;
		$access->canEdit		= ($user->gid < 25)? Ownservice::checkAccess('transaction','edit','transaction','all'):1;
		$access->canAdd			= ($user->gid < 25)? Ownservice::checkAccess('transaction','add','transaction','all'):1;
		$access->canDelete		= ($user->gid < 25)? Ownservice::checkAccess('transaction','delete','transaction','all'):1;
		
		$lists = array();
		
		if( ($user->gid >= 25) || ($level > 4) )
		{
			//Build filter branch select list
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );"');
		}

		//search filter
		$lists['search']	= $search;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;
		
		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('lists', $lists);
		$this->assignRef('params', $params);
		$this->assignRef('access', $access);
		$this->assignRef('db', $db);
		
		parent::display($tpl);
	}

	function _displayCustomerTransfers($tpl)
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		//get vars
		$params 	= $mainframe->getParams('com_ownservice');
		$gid			= $user->gid;
		$level			= $ownuser->get('level_id');

		if($gid < 25) {
			$canCustomerTransfers= Ownservice::checkAccess('transaction', 'customer', 'transaction', 'all');
			if ( !$canCustomerTransfers ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		JHTML::_('behavior.mootools');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');

		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		$filter_branch		= $mainframe->getUserStateFromRequest($option.'.customertransfers.filter_branch','filter_branch',0,'int' );
		$filter_order		= $mainframe->getUserStateFromRequest($option.'.customertransfers.filter_order', 'filter_order', 't.created', 'cmd');
		$filter_order_Dir	= $mainframe->getUserStateFromRequest($option.'.customertransfers.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search				= $mainframe->getUserStateFromRequest($option.'.customertransfers.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);

		//get data from the model
		$model 		= $this->getModel();
		$rows 		= & $this->get('CustomerTransfers');
		$total			= & $this->get('TotalCustomerTransfer');
		$branches 	= & $this->get('Branches');

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_CUSTOMER_TRANSFERS'));
		$document->setTitle( $params->get('page_title') );
		
		$limit			= $mainframe->getUserStateFromRequest($option.'.customertransfers.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart	= $mainframe->getUserStateFromRequest($option.'.customertransfers.limitstart', 'limitstart', 0, 'int' );

		$limitstart	= ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		jimport('joomla.html.pagination');
		$pageNav = new FMCPagination( $total, $limitstart, $limit );

		//search filter
		$lists['search']		= $search;
		
		$lists['order']		= $filter_order;
		$lists['order_Dir']	= $filter_order_Dir;

		$lists = array();

		if( ($user->gid == 25) || ($level > 4) ){
			//build filter branch select list
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'onchange="submitform( );"');
		}

		//assign data to document
		$this->assignRef('rows', $rows);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('lists', $lists);
		$this->assignRef('params', $params);
		$this->assignRef('db', $db);

		parent::display($tpl);
	}

	function _displayPaidTransactions($tpl) {

		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		//get vars
		$params 	= $mainframe->getParams('com_ownservice');
		$gid			= $user->gid;
		$level			= $ownuser->get('level_id');
		
		$filter_branch	= $mainframe->getUserStateFromRequest($option.'.paidtransactions.filter_branch','filter_branch',0,'int' );
		$filter_order		= $mainframe->getUserStateFromRequest($option.'.paidtransactions.filter_order', 'filter_order', 't.requested_date', 'cmd');
		$filter_order_Dir= $mainframe->getUserStateFromRequest($option.'.paidtransactions.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search			= $mainframe->getUserStateFromRequest($option.'.paidtransactions.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);
		
		if($gid < 25) {
			$canRequestApproval	= Ownservice::checkAccess('transaction', 'approval', 'transaction', 'all');
			if ( !$canRequestApproval ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		JHTML::_('behavior.mootools');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//Get data form the model
		$model		= $this->getModel();
		$rows			= & $this->get('PaidTransactions');
		$total			= & $this->get('TotalPaidTransactions');
		$branches 	= $model->getBranches();
		
		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_PAID_TRANSACTIONS'));
		$document->setTitle( $params->get('page_title') );
		
		//$limit			= $mainframe->getUserStateFromRequest($option.'.paidtransactions.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		//$limitstart	= $mainframe->getUserStateFromRequest($option.'.paidtransactions.limitstart', 'limitstart', 0, 'int' );

		//$limitstart	= ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		//jimport('joomla.html.pagination');
		//$pageNav = new FMCPagination( $total, $limitstart, $limit );
		
		$lists = array();

		if( ($user->gid == 25) || ($level > 4) ){
			//build filter branch select list
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'onchange="submitform( );"');
		}
		
		//search filter
		$lists['search']		= $search;
		
		$lists['order']		= $filter_order;
		$lists['order_Dir']	= $filter_order_Dir;

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		//$this->assignRef('pageNav', $pageNav);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('lists', $lists);
		
		parent::display($tpl);
		
	}

	function _displayrequestapproval($tpl) {

		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');

		//get vars
		$gid		= $user->gid;
		$level		= & $ownuser->get('level_id');
		
		$filter_branch	= $mainframe->getUserStateFromRequest($option.'.requestapproval.filter_branch','filter_branch',0,'int' );
		$filter_order	= $mainframe->getUserStateFromRequest($option.'.requestapproval.filter_order', 'filter_order', 't.requested_date', 'cmd');
		$filter_order_Dir= $mainframe->getUserStateFromRequest($option.'.requestapproval.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search			= $mainframe->getUserStateFromRequest($option.'.requestapproval.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);
		
		if($user->gid < 25) {
			$canTransfer = Ownservice::checkAccess('transaction', 'transfer', 'transaction', 'all');
			if ( !$canTransfer ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//JHTML::_('behavior.mootools');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');
		
		//Get data form the model
		$model		= $this->getModel();
		$rows		= & $this->get('Requestapproval');
		$total		= & $this->get('TotalRequestapproval');
		$receiving	= & $model->getReceiving();
		$branches 	= $model->getBranches();

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_REQUEST_APPROVEL'));
		$document->setTitle( $params->get('page_title') );

		$limit			= $mainframe->getUserStateFromRequest($option.'.requestapproval.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart		= $mainframe->getUserStateFromRequest($option.'.requestapproval.limitstart', 'limitstart', 0, 'int' );

		$limitstart = ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		jimport('joomla.html.pagination');
		$pageNav = new FMCPagination( $total, $limitstart, $limit );

		$lists = array();

		if( ($user->gid == 25) || ($level > 4) ){
			//build filter branch select list
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch, true, 'onchange="submitform( );"');
		}
		
		//search filter
		$lists['search']	= $search;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('receiving', $receiving);
		$this->assignRef('lists', $lists);

		parent::display($tpl);
	}

	function _displayElementrequestapproval($tpl=null, $cid) {

		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');

		//get vars
		$gid		= $user->gid;
		$level		= & $ownuser->get('level_id');

		if( $gid < 25 ) {
			$canTransfer= Ownservice::checkAccess('transaction', 'transfer', 'transaction', 'all');
			if ( !$canTransfer ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		$timeout	= JRequest::getVar('filter_time', '', 'post', 'string');

		JHTML::_('behavior.mootools');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-1.7.2.min.js');

		//ui
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/themes/base/jquery.ui.all.css');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/external/jquery.bgiframe-2.1.2.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/ui/jquery.ui.core.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/ui/jquery.ui.widget.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/ui/jquery.ui.mouse.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/ui/jquery.ui.draggable.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/ui/jquery.ui.position.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/ui/jquery.ui.resizable.js');
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/jquery-ui-1.9.1/ui/jquery.ui.dialog.js');

		$document->addScriptDeclaration('
			function showdialog() {
				    if(document.adminForm.transfer_id.value == "") {
						alert("'.JText::_('OWNSERVICE_SELECT_STAFF_TRANSFER').'");
						return false;
					}
					jQuery("#dialog").dialog();
			}
		');

		//Get data form the model
		$model		= $this->getModel();
		$rows		= & $this->get('Requestapproval');
		$receiving	= & $model->getReceiving();

		$lists = array();

		//build receiving
		$lists['receiving']	= OwnserviceHelper::buildreceivingselect($receiving, 'transfer_id','', true, 'class="inputbox"');

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('receiving', $receiving);
		$this->assignRef('lists', $lists);
		$this->assignRef('cid', $cid);

		parent::display($tpl);
	}

	function _displayrequestapprovalcorrected($tpl)
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$db			= & JFactory::getDbo();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$params 	= & $mainframe->getParams('com_ownservice');

		//get vars
		$gid		= $user->gid;
		$level		= & $ownuser->get('level_id');
		
		$filter_branch		= $mainframe->getUserStateFromRequest($option.'.requestapprovalcorrected.filter_branch','filter_branch',0,'int' );
		$filter_order		= $mainframe->getUserStateFromRequest($option.'.requestapprovalcorrected.filter_order', 'filter_order', 't.invoice', 'cmd');;
		$filter_order_dir	= $mainframe->getUserStateFromRequest($option.'.requestapprovalcorrected.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search				= $mainframe->getUserStateFromRequest($option.'.requestapprovalcorrected.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);

		if($user->gid < 25) {
			$canTransfer = Ownservice::checkAccess('transaction', 'transfer', 'transaction', 'all');
			if ( !$canTransfer ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//JHTML::_('behavior.mootools');
		
		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//Get data form the model
		$model			= $this->getModel();
		$rows			= & $this->get('Requestapprovalcorrected');
		$total			= & $this->get('TotalRequestapprovalcorrected');
		$branches		= $model->getBranches();

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_APPROVAL_PENDING_CORRECTED'));
		$document->setTitle( $params->get('page_title') );

		$limit			= $mainframe->getUserStateFromRequest($option.'.requestapprovalcorrected.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart		= $mainframe->getUserStateFromRequest($option.'.requestapprovalcorrected.limitstart', 'limitstart', 0, 'int' );

		$limitstart		= ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		jimport('joomla.html.pagination');
		$pageNav = new FMCPagination( $total, $limitstart, $limit );

		$lists = array();

		//build filter branch select list
		if( ($gid >= 25) || ($level > 4) ){
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );"');
		} 

		//search filter
		$lists['search']	= $search;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('lists', $lists);
		$this->assignRef('db', $db);
		
		parent::display($tpl);
	}

	function _displayReceivingtransfer() {

		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();

		//get vars
		$gid		= $user->gid;
		$level		= & $ownuser->get('level_id');
		$params 	= & $mainframe->getParams('com_ownservice');
		
		$filter_order	= $mainframe->getUserStateFromRequest($option.'.transferring.filter_order', 'filter_order', 't.invoice', 'cmd');
		$filter_order_dir= $mainframe->getUserStateFromRequest($option.'.transferring.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		
		$search				= $mainframe->getUserStateFromRequest($option.'.transferring.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);

		if($gid < 25) {
			$canTransferred = Ownservice::checkAccess('transaction', 'transferred', 'transaction', 'all');
			if ( !$canTransferred ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//JHTML::_('behavior.mootools');

		//Set layout
		$this->setLayout('receivingtransfer');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//Get data form the model
		$model		= $this->getModel();
		$rows			= & $this->get('TransferringDateSession');
		$total			= & $this->get('TotalTransferring');
		//$pageNav	= & $this->get('Pagination');

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_TRANSACTIONS'));
		$document->setTitle( $params->get('page_title') );
		
		//$limit		= $mainframe->getUserStateFromRequest($option.'.transferring.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		//$limitstart	= $mainframe->getUserStateFromRequest($option.'.transferring.limitstart', 'limitstart', 0, 'int' );

		//$limitstart	= ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		jimport('joomla.html.pagination');
		//$pageNav = new FMCPagination( $total, $limitstart, $limit );

		$lists = array();
		
		//search filter
		$lists['search']	= $search;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_dir;

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		$this->assignRef('ownuser', $ownuser);
		//$this->assignRef('access', $access);
		//$this->assignRef('pageNav', $pageNav);
		$this->assignRef('total', $total);
		$this->assignRef('lists', $lists);

		parent::display($tpl);
	}

	function _displayfailedtransactions($tpl)
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$db			= & JFactory::getDBO();

		//get vars
		$gid		= $user->gid;
		$level		= $ownuser->get('level_id');
		$params 	= & $mainframe->getParams('com_ownservice');
		
		if($gid < 25) {
			$canF = Ownservice::checkAccess('transaction', 'failed', 'transaction', 'all');
			if ( !$canF ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		$filter_branch		= $mainframe->getUserStateFromRequest($option.'.failedtransaction.filter_branch','filter_branch',0,'int' );
		$filter_order	= $mainframe->getUserStateFromRequest($option.'.failedtransaction.filter_order', 'filter_order', 't.invoice', 'cmd');
		$filter_order_dir= $mainframe->getUserStateFromRequest($option.'.failedtransaction.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search				= $mainframe->getUserStateFromRequest($option.'.failedtransaction.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);

		//Get data form the model
		$model		= $this->getModel();
		$rows		= & $this->get('FailedTransactions');
		$total		= & $this->get('TotalFailedTransactions');
		$branches	= $model->getBranches();

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_FAILED_TRANSACTIONS'));
		$document->setTitle( $params->get('page_title') );

		$limit			= $mainframe->getUserStateFromRequest($option.'.failedtransaction.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart	= $mainframe->getUserStateFromRequest($option.'.failedtransaction.limitstart', 'limitstart', 0, 'int' );

		$limitstart	= ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		jimport('joomla.html.pagination');
		$pageNav = new FMCPagination( $total, $limitstart, $limit );

		$lists = array();

		//build filter branch select list
		if( ($gid >= 25) || ($level > 4) ){
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );"');
		} 

		//search filter
		$lists['search']	= $search;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('lists', $lists);
		$this->assignRef('db', $db);
		
		parent::display($tpl);
	}

	function _displaycancelledtransactions($tpl)
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$db			= & JFactory::getDbo();

		//get vars
		$gid		= $user->gid;
		$level		= $ownuser->get('level_id');
		$params 	= & $mainframe->getParams('com_ownservice');
		
		$filter_branch		= $mainframe->getUserStateFromRequest($option.'.cancelledtransaction.filter_branch','filter_branch',0,'int' );
		$filter_order		= $mainframe->getUserStateFromRequest($option.'.cancelledtransaction.filter_order', 'filter_order', 't.invoice', 'cmd');;
		$filter_order_dir	= $mainframe->getUserStateFromRequest($option.'.cancelledtransaction.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search				= $mainframe->getUserStateFromRequest($option.'.cancelledtransaction.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);

		if($gid < 25) {
			$canC = Ownservice::checkAccess('transaction', 'cancelled', 'transaction', 'all');
			if ( !$canC ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//JHTML::_('behavior.mootools');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		//Get data form the model
		$model			= $this->getModel();
		$rows			= & $this->get('CancelledTransactions');
		$total			= & $this->get('TotalCancelledTransactions');
		$branches		= $model->getBranches();

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_CANCELLED_TRANSACTIONS'));
		$document->setTitle( $params->get('page_title') );

		$limit			= $mainframe->getUserStateFromRequest($option.'.cancelledtransaction.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart		= $mainframe->getUserStateFromRequest($option.'.cancelledtransaction.limitstart', 'limitstart', 0, 'int' );

		$limitstart		= ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		jimport('joomla.html.pagination');
		$pageNav = new FMCPagination( $total, $limitstart, $limit );

		// Create a user access object for the current user
		$access = new stdClass();
		$access->canDelete		= ($gid < 25)? Ownservice::checkAccess('transaction','delete','transaction','all'):1;

		$lists = array();

		//build filter branch select list
		if( ($gid >= 25) || ($level > 4) ){
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );"');
		} 

		//search filter
		$lists['search']	= $search;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('lists', $lists);
		$this->assignRef('db', $db);
		$this->assignRef('access', $access);
		
		parent::display($tpl);
	}

	function _displaycorrectedtransactions($tpl)
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user		= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$db			= & JFactory::getDbo();
		
		//get vars
		$gid		= $user->gid;
		$level		= $ownuser->get('level_id');
		$params 	= & $mainframe->getParams('com_ownservice');

		if($gid < 25) {
			$canC = Ownservice::checkAccess('transaction', 'corrected', 'transaction', 'all');
			if ( !$canC ) {
				JError::raiseWarning(500, JText::_('ALERTNOTAUTH') );
				$mainframe->redirect(JRoute::_('index.php?option=com_ownservice'));
			}
		}

		//JHTML::_('behavior.mootools');

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/icon.css');
		//add java script to document
		$document->addScript(JURI::base().'components/com_ownservice/assets/js/ownservice.js');

		$filter_branch		= $mainframe->getUserStateFromRequest($option.'.correctedtransaction.filter_branch','filter_branch',0,'int' );
		$filter_order		= $mainframe->getUserStateFromRequest($option.'.correctedtransaction.filter_order', 'filter_order', 't.invoice', 'cmd');;
		$filter_order_dir	= $mainframe->getUserStateFromRequest($option.'.correctedtransaction.filter_order_Dir', 'filter_order_Dir', 'DESC', 'cmd');
		$search				= $mainframe->getUserStateFromRequest($option.'.correctedtransaction.search', 'search', '', 'string' );
		if (strpos($search, '"') !== false) {
			$search = str_replace(array('=', '<'), '', $search);
		}
		$search = JString::strtolower($search);

		//Get data form the model
		$model			= $this->getModel();
		$rows			= & $this->get('CorrectedTransactions');
		$total			= & $this->get('TotalCorrectedTransactions');
		$branches		= $model->getBranches();

		//set page title
		$params->set('page_title',	JText::_('OWNSERVICE_CORRECTED_TRANSACTIONS'));
		$document->setTitle( $params->get('page_title') );

		$limit			= $mainframe->getUserStateFromRequest($option.'.correctedtransaction.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
		$limitstart		= $mainframe->getUserStateFromRequest($option.'.correctedtransaction.limitstart', 'limitstart', 0, 'int' );

		$limitstart		= ( $limit != 0 ? (floor($limitstart / $limit) * $limit) : 0 );

		jimport('joomla.html.pagination');
		$pageNav = new FMCPagination( $total, $limitstart, $limit );

		$lists = array();

		//build filter branch select list
		if( ($gid >= 25) || ($level > 4) ){
			$lists['branch'] = OwnserviceHelper::buildbranchesselect($branches, 'filter_branch',$filter_branch,true, 'class="inputbox" onchange="submitform( );"');
		} 

		//search filter
		$lists['search']	= $search;
		
		$lists['order']     = $filter_order;
		$lists['order_Dir'] = $filter_order_Dir;

		$this->assignRef('rows', $rows);
		$this->assignRef('user', $user);
		$this->assignRef('pageNav', $pageNav);
		$this->assignRef('ownuser', $ownuser);
		$this->assignRef('lists', $lists);
		$this->assignRef('db', $db);
		
		parent::display($tpl);
	}

	function _displaytransferring($tpl)
	{
		global $mainframe, $option;

		//Initialize variables
		$document	= & JFactory::getDocument();
		$user			= & JFactory::getUser();
		$ownuser	= & Ownservice::getUser();
		$db			= & JFactory::getDbo();
		$params 	= & $mainframe->getParams('com_ownservice');
		$pathway  	= & $mainframe->getPathway();
		
		//Set page title information
		$menus		= &JSite::getMenu();
		$menu		= $menus->getActive();

		//add css to document
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/style.css');
		$document->addStyleSheet(JURI::base().'components/com_ownservice/assets/css/nav.css');

		//get data from the model
		$model			= $this->getModel();
		$rows				= $this->get( 'TransferringTransactions' ); 

		//echo '<pre>'; print_r($rows); echo '</pre>';

		// because the application sets a default page title, we need to get it
		// right from the menu item itself
		if (is_object( $menu )) {
			$menu_params = new JParameter( $menu->params );
			if (!$menu_params->get( 'page_title')) {
				$params->set('page_title',	JText::_('OWNSERVICE_TRANSFERRING_TRANSACTIONS'));
			}
		} else {
			$params->set('page_title',	JText::_('OWNSERVICE_TRANSFERRING_TRANSACTIONS'));
		}
		$document->setTitle( $params->get( 'page_title' ) );

		$this->assignRef('rows', $rows);
		$this->assignRef('params', $params);

		parent::display($tpl);
	}
}